#ifndef __APP_PROXY_H_
#define __APP_PROXY_H_

#include "xmsg.h"

#ifdef __cplusplus
extern "C" {
#endif



/****************************************************************************
*
* app proxy
*
****************************************************************************/

#define RESOURCE_ID_TYPE_MASK	0xC0000000
#define RESOURCE_CLASS_MASK 	0x3FFF0000
#define RESOURCE_TYPE_MASK 		0x0000FFC0
#define RESOURCE_VERSION_MASK 	0x0000003F

#define PRIVATE_RESOURCE_ID_TYPE 		0xC0000000
#define PRIVATE_RESOURCE_DEFINER_MASK  	0x3FF00000
#define PRIVATE_RESOURCE_IDENTITY_MASK	0x000FFFFF

#define RM_RESOURCE_ID 	     0x00010041
#define AI_RESOURCE_ID 	     0x00020041
#define CAS_RESOURCE_ID      0x00030041
#define DT_RESOURCE_ID       0x00240041
#define MMI_RESOURCE_ID      0x00400041
#define SAS_RESOURCE_ID      0x00961001
#define CI_HC_RESOURCE_ID_V1	0x00200041


#define RESOURCE_COUNT		32
typedef struct
{
	unsigned long 	m_ressId; 		//0--this element is empty; 1 -- used;
	unsigned char 	m_isLocalRess;     ////1 -- local resource; 0 -- remote resource
	int (*m_funOnMessage)(xmsg_t* pXmsg);// available when is local resource
	unsigned char 	m_tcid;				//available when is remote resource,
}resource_t;

extern resource_t g_tab_ress[RESOURCE_COUNT];

int appproxy_task(void* param);
void send_app_apdu_to_proxy(unsigned short ssnb, unsigned long apduTag,
					unsigned char* pbApduBody, int apduBodyLen);
unsigned char * decode_apdu(unsigned char* pbApdu, unsigned long * pdwApduTag,
							unsigned long * pdwLengthField);



/****************************************************************************
*
* RM resource
*
****************************************************************************/

int rm_init(void);
int rm_on_message(xmsg_t* pXmsg);



/****************************************************************************
*
* AI resource
*
****************************************************************************/

int ai_on_message(xmsg_t* pXmsg);
int ai_init();
int ai_enter_menu (unsigned char appIndex);


int mmi_on_message(xmsg_t* pXmsg);


/****************************************************************************
*
* CAS resource
*
****************************************************************************/

int cas_init();
int cas_on_message(xmsg_t* pXmsg);


/****************************************************************************
*
* DT(datetime) resource
*
****************************************************************************/

int dt_init();
int dt_on_message(xmsg_t* pXmsg);




/************************************************************************/
/*                                                                      */
/************************************************************************/
void sendPrivateResourceAPDU(unsigned char u8CISlot, unsigned short u16SessionNB,
							 const unsigned char*pu8APDUData, unsigned int u32APDULen);//Send APDU of Private Resource to CICAM. 

void closePrivateSession(unsigned char u8CISlot, unsigned short u16SessionNB);

int registerPrivateResourceToAgent(unsigned int u32ResourceID, int (*f_ResourceConnect)(unsigned char , unsigned short),
										 void (*f_ResourceData)(unsigned char, unsigned short, unsigned char*), void (*f_ResourceClose)(unsigned char, unsigned short));//Register Customer Private Resource to Resource Agent. 



/************************************************************************/
/* Operator Profile resource                                            */
/************************************************************************/

//************************************
// Method:    Operator Profile Initialization. Should be called as soon as possible
// FullName:  CI_OpInit
// Access:    public 
// Returns:   int
//	OK			Success
//	Other		Failure
// Qualifier:
// Parameter: void
//************************************
int CI_OpInit(void);
/****************************************************************************
*
* end
*
****************************************************************************/

/****************************************************************************
*
* AD resource
*
****************************************************************************/
int ad_on_message(xmsg_t* pXmsg);

int hc_init(void);
int hc_on_message(xmsg_t* pXmsg);


#ifdef __cplusplus
}
#endif

#endif //__APP_PROXY_H_
